console.log('导入是否正确：', Qs, '===', axios);

//#region qs的测试部分

let div1 = document.getElementById('div1');

let json = {
  id: 100,
  info: '浏阵鱼',
};

// qs的功能就是转换json为查询字符串（get提交数据的格式）
div1.innerHTML = Qs.stringify(json);

let query = 'id=%E6%B5%8F%E9%98%B5%E9%B1%BC;';
console.log('还原查询字符串为json：', Qs.parse(query));

query =
  '?ie=utf-8&f=3&rsv_bp=1&tn=baidu&wd=黑暗骑士&oq=%25E9%25BB%2591%25E6%259A%2597%25E9%25AA%2591&rsv_pq=c112664d001b111d&rsv_t=32e79NlaRnm8uzdy0ALo%2BludcCn7sFiSQ%2FQRuNEig1k2cG6KkLg5qVGUPjw&rqlang=cn&rsv_dl=ts_0&rsv_enter=1&rsv_sug3=1&rsv_sug1=1&rsv_sug7=100&rsv_sug2=1&rsv_btype=t&prefixsug=%25E9%25BB%2591%25E6%259A%2597%25E9%25AA%2591&rsp=0&rsv_sug4=1061';
console.log('还原查询字符串为json：', Qs.parse(query));

query =
  '?spm_id_from=333.1007.tianma.1-2-2.click&vd_source=c85fe710bd7a7ecf12c5e46b39f4f983';
console.log('还原查询字符串为json：', Qs.parse(query));

// #endregion

//#region ajax请求功能演示
let txtecho = document.getElementById('txtecho');
let btnecho = document.getElementById('btnecho');
let divecho = document.getElementById('divecho');

const BASE_URL = 'https://api.huhuiyu.top';

btnecho.addEventListener('click', () => {
  let promise = axios({
    url: BASE_URL + '/test/echo?echo=' + txtecho.value,
    data: '',
    method: 'get',
  });

  promise
    .then((resp) => {
      // divecho.innerHTML = JSON.stringify(resp.data);
      divecho.innerHTML = resp.data.data;
    })
    .catch((err) => {
      console.error('应用程序异常：', err);
    });
});
// #endregion

//#region 足球俱乐部查询演示
let btnFootball = document.getElementById('btnFootball');
let divFootball = document.getElementById('divFootball');

btnFootball.addEventListener('click', () => {
  // json格式的参数
  let params = {
    orderBy: 1,
    pageNumber: 1,
    pageSize: 5,
  };
  // 转换参数为查询字符串格式
  let data = Qs.stringify(params);
  console.log('传递的数据: ', data);
  // 发起请求
  let promise = axios({
    url: BASE_URL + '/crud/footballteam?' + data,
    data: '',
    method: 'get',
  });

  promise
    .then((resp) => {
      divFootball.innerHTML = JSON.stringify(resp.data, null, 2);
    })
    .catch((err) => {
      console.error(err);
    });
});

// #endregion
